package DAO.impl;

import java.util.List;

import model.impl.Passenger;
import model.impl.Ticket;

import org.hibernate.Query;

import DAO.TicketDAO;

/**
 *  Implements TicketDAO interface, extend GenericDAOImpl class using as 
 *  parameters entity of Ticket and Integer class as an ID. It also adds some 
 *  specific to Ticket entity methods.
 */
public class TicketDAOImpl extends GenericDAOImpl<Ticket, Integer> implements
		TicketDAO {

	/**
	 * Checks given passenger and looks for all passenger's tickets
	 * it.
	 * 
	 * @param  passenger - Passenger entity for where to look for tickets
	 * @return      	 - List of tickets of the given passenger or null 
	 * 					   if there	is no passengers on train
	 */
	public List<Ticket> getAllTickets(Passenger passenger) {
		List<Ticket> tickets = null;

		String sqlRequest = "SELECT t FROM Ticket t WHERE t.passenger = :givenPassenger";
		Query query = this.getSession().createSQLQuery(sqlRequest)
				.setParameter("givenPassenger", passenger);
		tickets = this.findMany(query);

		return tickets;
	}
}
